package com.example.application;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;

import com.example.application.task.WeatherTask1;

import java.util.List;

public class WeatherActivity3 extends AppCompatActivity {
    Handler handler;
    String TAG="MainActivity";
    private ProgressBar bar;
    SimpleAdapter listItemAdapter;
    List<String> list;
    GridView gridView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ins_list);
        GridView mylist = findViewById(R.id.mylistview);
        bar=findViewById(R.id.progressBar);
        mylist.setEmptyView(bar);
        handler = new Handler(Looper.myLooper()) {
            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what == 5) {
                    list = (List<String>) msg.obj;
                    //String[] list_data={};
                    ListAdapter adapter = new ArrayAdapter<String>(WeatherActivity3.this,android.R.layout.simple_list_item_1,list);
                    //gridView = findViewById(R.id.mylist);
                    mylist.setAdapter(adapter);
                    //mylist.setEmptyView(findViewById(R.id.nodata));
                    //隐藏bar
                    //bar.setVisibility(View.INVISIBLE);
                }
                super.handleMessage(msg);
            }
        };
        WeatherTask1 mytask=new WeatherTask1();
        mytask.setHandler(handler);
        Thread t = new Thread(mytask);
        t.start();
    }
    }
